home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 7 / Apprentice-Release7.iso / Source Code / C / Applications / Tcl-Tk 8.0 / Pre-installed version / tcl8.0 / tests / lsearch.test < prev    next >
Encoding:
Text File  |  1997-08-15  |  2.7 KB  |  87 lines  |  [TEXT/ALFA]

  1. # Commands covered:  lsearch
  2. #
  3. # This file contains a collection of tests for one or more of the Tcl
  4. # built-in commands.  Sourcing this file into Tcl runs the tests and
  5. # generates output for errors.  No output means no errors were found.
  6. #
  7. # Copyright (c) 1991-1993 The Regents of the University of California.
  8. # Copyright (c) 1994 Sun Microsystems, Inc.
  9. #
  10. # See the file "license.terms" for information on usage and redistribution
  11. # of this file, and for a DISCLAIMER OF ALL WARRANTIES.
  12. #
  13. # SCCS: @(#) lsearch.test 1.7 97/04/30 13:23:53
  14.  
  15. if {[string compare test [info procs test]] == 1} then {source defs}
  16.  
  17. set x {abcd bbcd 123 234 345}
  18. test lsearch-1.1 {lsearch command} {
  19.     lsearch $x 123
  20. } 2
  21. test lsearch-1.2 {lsearch command} {
  22.     lsearch $x 3456
  23. } -1
  24. test lsearch-1.3 {lsearch command} {
  25.     lsearch $x *5
  26. } 4
  27. test lsearch-1.4 {lsearch command} {
  28.     lsearch $x *bc*
  29. } 0
  30.  
  31. test lsearch-2.1 {search modes} {
  32.     lsearch -exact {xyz bbcc *bc*} *bc*
  33. } 2
  34. test lsearch-2.2 {search modes} {
  35.     lsearch -exact {b.x ^bc xy bcx} ^bc
  36. } 1
  37. test lsearch-2.3 {search modes} {
  38.     lsearch -exact {foo bar cat} ba
  39. } -1
  40. test lsearch-2.4 {search modes} {
  41.     lsearch -exact {foo bar cat} bart
  42. } -1
  43. test lsearch-2.5 {search modes} {
  44.     lsearch -exact {foo bar cat} bar
  45. } 1
  46. test lsearch-2.6 {search modes} {
  47.     list [catch {lsearch -regexp {xyz bbcc *bc*} *bc*} msg] $msg
  48. } {1 {couldn't compile regular expression pattern: ?+* follows nothing}}
  49. test lsearch-2.7 {search modes} {
  50.     lsearch -regexp {b.x ^bc xy bcx} ^bc
  51. } 3
  52. test lsearch-2.8 {search modes} {
  53.     lsearch -glob {xyz bbcc *bc*} *bc*
  54. } 1
  55. test lsearch-2.9 {search modes} {
  56.     lsearch -glob {b.x ^bc xy bcx} ^bc
  57. } 1
  58. test lsearch-2.10 {search modes} {
  59.     list [catch {lsearch -glib {b.x bx xy bcx} b.x} msg] $msg
  60. } {1 {bad search mode "-glib": must be -exact, -glob, or -regexp}}
  61.  
  62. test lsearch-3.1 {lsearch errors} {
  63.     list [catch lsearch msg] $msg
  64. } {1 {wrong # args: should be "lsearch ?mode? list pattern"}}
  65. test lsearch-3.2 {lsearch errors} {
  66.     list [catch {lsearch a} msg] $msg
  67. } {1 {wrong # args: should be "lsearch ?mode? list pattern"}}
  68. test lsearch-3.3 {lsearch errors} {
  69.     list [catch {lsearch a b c} msg] $msg
  70. } {1 {bad search mode "a": must be -exact, -glob, or -regexp}}
  71. test lsearch-3.4 {lsearch errors} {
  72.     list [catch {lsearch a b c d} msg] $msg
  73. } {1 {wrong # args: should be "lsearch ?mode? list pattern"}}
  74. test lsearch-3.5 {lsearch errors} {
  75.     list [catch {lsearch "\{" b} msg] $msg
  76. } {1 {unmatched open brace in list}}
  77.  
  78. test lsearch-4.1 {binary data} {
  79.     lsearch -exact [list foo one\000two bar] bar
  80. } 2
  81. test lsearch-4.2 {binary data} {
  82.     set x one
  83.     append x \x00
  84.     append x two
  85.     lsearch -exact [list foo one\000two bar] $x
  86. } 1
  87.